package models;

import java.io.Serializable;
import javax.persistence.*;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The persistent class for the addr database table.
 * 
 */
@Entity
@Table(name = "ADDR")
public class Addr implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @TableGenerator(
            name = "ADDR_SEQ",
            table = "SEQUENCE",
            pkColumnName = "NAME",
            pkColumnValue = "ADDR_SEQ",
            valueColumnName = "CNT",
            initialValue = 10000,
            allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "ADDR_SEQ")
    @Column(unique = true, nullable = false)
    private Integer id;

    private Integer aid;

    @Column(length = 20)
    private String city;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CREATE_D")
    private Date createD;

    @Column(name = "EMPLOYMENT_ID")
    private Integer employmentId;

    private int ownership;

    @Column(length = 20)
    private String province;

    @Column(name = "STREET_INFO", length = 500)
    private String streetInfo;

    private int type;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "UPDATE_D")
    private Date updateD;

    @Column(name = "VERIFY_STATUS")
    private int verifyStatus;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "VERIFY_STATUS_D")
    private Date verifyStatusD;

    @Column(name = "YEARS_LIVED")
    private int yearsLived;

    @Column(name = "LAND_PHONE")
    private String landPhone;

    @Column(name = "LAND_PHONE_EXT")
    private String landPhoneExt;

    public Addr() {
    }

    public void setValues(Integer aid, Integer empId, String streetAddress, String city, String province,
            String landPhone, YearsLived yearsLived, Ownership ownerShip, String landPhoneExt) {
        if (StringUtils.isNotEmpty(streetAddress))
            this.setStreetInfo(streetAddress);
        if (StringUtils.isNotEmpty(province))
            this.setProvince(province);
        if (StringUtils.isNotEmpty(city))
            this.setCity(city);
        if (yearsLived != null)
            this.setYearsLived(yearsLived);
        if (ownerShip != null)
            this.setOwnership(ownerShip);
        if (StringUtils.isNotEmpty(landPhone))
            this.setLandPhone(landPhone);
        if (aid != null)
            this.setAid(aid);
        if (empId != null)
            this.setEmploymentId(empId);
        if(StringUtils.isNotEmpty(landPhoneExt))
            this.setLandPhoneExt(landPhoneExt);
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getAid() {
        return this.aid;
    }

    public void setAid(Integer aid) {
        this.aid = aid;
    }

    public String getCity() {
        return this.city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public Date getCreateD() {
        return this.createD;
    }

    public void setCreateD(Date createD) {
        this.createD = createD;
    }

    public int getEmploymentId() {
        return this.employmentId;
    }

    public void setEmploymentId(int employmentId) {
        this.employmentId = employmentId;
    }

    public Ownership getOwnership() {
        return Ownership.values()[this.ownership];
    }

    public void setOwnership(Ownership ownership) {
        this.ownership = ownership.ordinal();
    }

    public String getProvince() {
        return this.province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getStreetInfo() {
        return this.streetInfo;
    }

    public void setStreetInfo(String streetInfo) {
        this.streetInfo = streetInfo;
    }

    public int getType() {
        return this.type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Date getUpdateD() {
        return this.updateD;
    }

    public void setUpdateD(Date updateD) {
        this.updateD = updateD;
    }

    public int getVerifyStatus() {
        return this.verifyStatus;
    }

    public void setVerifyStatus(int verifyStatus) {
        this.verifyStatus = verifyStatus;
    }

    public Date getVerifyStatusD() {
        return this.verifyStatusD;
    }

    public void setVerifyStatusD(Date verifyStatusD) {
        this.verifyStatusD = verifyStatusD;
    }

    public YearsLived getYearsLived() {
        return YearsLived.values()[this.yearsLived];
    }

    public void setYearsLived(YearsLived yearsLived) {
        this.yearsLived = yearsLived.ordinal();
    }

    public String getLandPhone() {
        return landPhone;
    }

    public void setLandPhone(String landPhone) {
        this.landPhone = landPhone;
    }

    public String getLandPhoneExt() {
        return landPhoneExt;
    }

    public void setLandPhoneExt(String landPhoneExt) {
        this.landPhoneExt = landPhoneExt;
    }

    public enum YearsLived {
        LESS_THAN_ONE("LT1"),
        FROM_1_TO_2("1-2"),
        FROM_2_TO_4("2-4"),
        FROM_4_TO_6("4-6"),
        FROM_6_TO_8("6-8"),
        FROM_8_TO_10("8-10"),
        MORE_THAN_10("MT10");
        private String _label;

        private YearsLived(String label) {
            this._label = label;
        }

        public String getLabel() {
            return this._label;
        }

    }

    public enum Ownership {
        ANY("Any"), // 0 -
        OWN("Fully Own"), // 1 -
        RENT("Rent"), // 2 -
        MORTGAGE("Pay Mortgage on"), // 3-
        ;

        String m_label;

        Ownership(String label) {
            m_label = label;
        }

        public String getLabel() {
            return m_label;
        }

        public static List<Ownership> getOwnershipList() {
            List<Ownership> ownershipList = new ArrayList<Ownership>();
            ownershipList.add(Ownership.RENT);
            ownershipList.add(Ownership.OWN);
            ownershipList.add(Ownership.MORTGAGE);
            return ownershipList;
        }
    }

}